package com.zxy.demo.guava;

import com.google.common.collect.Ordering;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import static com.google.common.collect.Ordering.natural;

/**
 * OrderingDemo.
 * 
 * Created by zxybird on 17/3/13.
 */
public class OrderingDemo {

  public static void main(String[] args) {
    List<Integer> list = new ArrayList<Integer>();

    list.add(5);
    list.add(8);
    list.add(1);
    list.add(4);

    Comparator<Integer> comparator = new Comparator<Integer>() {
      @Override
      public int compare(Integer o1, Integer o2) {
        return o1 - o2;
      }
    };

    Ordering<Integer> ordering = new Ordering<Integer>() {
      @Override
      public int compare(Integer left, Integer right) {
        return left - right;
      }
    }.reverse();

    Ordering<Integer> ordering1 = Ordering.natural().reverse();

    Collections.sort(list, ordering);
//    Collections.sort(list, ordering1);


    for (Integer i : list) {
      System.out.println(i);
    }

  }

}
